﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace K3R {
	public enum SiteMode {
		Development, Test, Uat, Live
	}

	public class Config : ConfigurationSection {
		[ConfigurationProperty("connectionStringName", DefaultValue = "")]
		public string ConnectionStringName {
			get {
				return (string)base["connectionStringName"];
			}
			set {
				base["connectionStringName"] = value;
			}
		}

		[ConfigurationProperty("mode", DefaultValue = SiteMode.Development)]
		public SiteMode Mode {
			get {
				return (SiteMode)base["mode"];
			}
			set {
				base["mode"] = value;
			}
		}
	}

	public static class Settings {
		private static Config _settings = (Config)ConfigurationManager.GetSection("k3r");

		static Settings() { }

		public static SiteMode Mode {
			get {
				return _settings.Mode;
			}
		}

		public static string ConnectionString {
			get {
				string connectionString = null;

				if (_settings != null)
					connectionString = ConfigurationManager.ConnectionStrings[(_settings.ConnectionStringName != ""
						? _settings.ConnectionStringName
						: _settings.Mode.ToString())].ConnectionString;

				return connectionString;
			}
		}
	}
}
